#include "script_util.h"

void drop_enter (char  *str)
{
    while (*str !='\0')
    {
        /* code */
        if  (*str == '\n') {
            *str = '\0';
            break;
        }
        str++;
    }
    
}

void exec_script_string(char *script, char *res){
    FILE *fd;
    char result[20];
    fd = popen(script, "r");
    fgets(result, sizeof(result),fd);
    pclose(fd);
    drop_enter(result);
    strcpy(res, result);
}
int exec_script_int(char *script){
    FILE *fd;
    int res;
    char result[20];
    fd = popen(script, "r");
    fgets(result, sizeof(result),fd);
    pclose(fd);
    sscanf(result, "%d", &res);
    return res;
}
float exec_script_float(char *script){
    FILE *fd;
    float res;
    char result[20];
    fd = popen(script, "r");
    fgets(result, sizeof(result),fd);
    pclose(fd);
    sscanf(result, "%f", &res);
    return res;
}
